package com.zhaokuner.pm.ctrl;

import com.zhaokuner.pm.common.utils.RestClientUtil;
import com.zhaokuner.pm.model.NodeBO;
import com.zhaokuner.pm.model.common.BaseList;
import com.zhaokuner.pm.model.common.BaseRespBean;
import com.zhaokuner.pm.model.vo.NodeVO;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 类描述:列表
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/8/23 16:19
 */
@RestController
@RequestMapping("query")
public class QueryCtrl {

    @RequestMapping("list")
    public Object list() {
        BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
        queryBuilder.must(QueryBuilders.termQuery("periodical", "6.29"));
        queryBuilder.must(QueryBuilders.termQuery("bizName", "用户"));
        int pageIndex = 1;
        int pageSize = 100;
        List<SortBuilder<?>> sortList = Arrays.asList(
                // new FieldSortBuilder("periodicalOrder").order(SortOrder.DESC),
                new FieldSortBuilder("rank").order(SortOrder.ASC)
        );
        BaseList<NodeVO> list = RestClientUtil.list(queryBuilder, pageIndex, pageSize, sortList, NodeVO.class);
        return list;
    }

    @RequestMapping("get")
    public Object get() {
        BaseRespBean<NodeBO> bean = RestClientUtil.getById("a", NodeBO.class);
        return bean;
    }

}
